---
page_title: "cloudflare_list Resource - Cloudflare"
subcategory: ""
description: |-
  Provides Lists (IPs, Redirects, Hostname, ASNs) to be used in Edge
  Rules Engine across all zones within the same account.
---

# cloudflare_list (Resource)

Provides Lists (IPs, Redirects, Hostname, ASNs) to be used in Edge
Rules Engine across all zones within the same account.

~> The `cloudflare_list` resource supports defining list items in line with the
  `item` attribute. The provider also has a `cloudflare_list_item` resource for
  managing items as independent resources. Using both in line `item` definitions
  _and_ `cloudflare_list_items` on the same list is not supported and will cause
  Terraform into an irreconcilable state.

## Example Usage

```terraform
# IP list
resource "cloudflare_list" "example" {
  account_id  = "f037e56e89293a057740de681ac9abbe"
  name        = "example_list"
  description = "example IPs for a list"
  kind        = "ip"

  item {
    value {
      ip = "192.0.2.0"
    }
    comment = "one"
  }

  item {
    value {
      ip = "192.0.2.1"
    }
    comment = "two"
  }
}

# Redirect list
resource "cloudflare_list" "example" {
  account_id  = "f037e56e89293a057740de681ac9abbe"
  name        = "example_list"
  description = "example redirects for a list"
  kind        = "redirect"

  item {
    value {
      redirect {
        source_url = "example.com/blog"
        target_url = "https://blog.example.com"
      }
    }
    comment = "one"
  }

  item {
    value {
      redirect {
        source_url            = "example.com/foo"
        target_url            = "https://foo.example.com"
        include_subdomains    = "enabled"
        subpath_matching      = "enabled"
        status_code           = 301
        preserve_query_string = "enabled"
        preserve_path_suffix  = "disabled"
      }
    }
    comment = "two"
  }
}

# ASN list
resource "cloudflare_list" "example" {
  account_id  = "f037e56e89293a057740de681ac9abbe"
  name        = "example_list"
  description = "example ASNs for a list"
  kind        = "asn"

  item {
    value {
      asn = 677
    }
    comment = "one"
  }

  item {
    value {
     asn = 989
    }
    comment = "two"
  }
}


# Hostname list
resource "cloudflare_list" "example" {
  account_id  = "f037e56e89293a057740de681ac9abbe"
  name        = "example_list"
  description = "example hostnames for a list"
  kind        = "hostname"

  item {
    value {
      hostname {
        url_hostname = "example.com"
      }
    }
    comment = "one"
  }

  item {
    value {
      hostname {
        url_hostname = "*.example.com"
      }
    }
    comment = "two"
  }
}
```
<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `account_id` (String) The account identifier to target for the resource.
- `kind` (String) The type of items the list will contain. Available values: `ip`, `redirect`, `hostname`, `asn`. **Modifying this attribute will force creation of a new resource.**
- `name` (String) The name of the list. **Modifying this attribute will force creation of a new resource.**

### Optional

- `description` (String) An optional description of the list.
- `item` (Block Set) (see [below for nested schema](#nestedblock--item))

### Read-Only

- `id` (String) The ID of this resource.

<a id="nestedblock--item"></a>
### Nested Schema for `item`

Required:

- `value` (Block List, Min: 1, Max: 1) (see [below for nested schema](#nestedblock--item--value))

Optional:

- `comment` (String) An optional comment for the item.

<a id="nestedblock--item--value"></a>
### Nested Schema for `item.value`

Optional:

- `asn` (Number)
- `hostname` (Block List) (see [below for nested schema](#nestedblock--item--value--hostname))
- `ip` (String)
- `redirect` (Block List) (see [below for nested schema](#nestedblock--item--value--redirect))

<a id="nestedblock--item--value--hostname"></a>
### Nested Schema for `item.value.hostname`

Required:

- `url_hostname` (String) The FQDN to match on. Wildcard sub-domain matching is allowed. Eg. *.abc.com.


<a id="nestedblock--item--value--redirect"></a>
### Nested Schema for `item.value.redirect`

Required:

- `source_url` (String) The source url of the redirect.
- `target_url` (String) The target url of the redirect.

Optional:

- `include_subdomains` (String) Whether the redirect also matches subdomains of the source url. Available values: `disabled`, `enabled`.
- `preserve_path_suffix` (String) Whether to preserve the path suffix when doing subpath matching. Available values: `disabled`, `enabled`.
- `preserve_query_string` (String) Whether the redirect target url should keep the query string of the request's url. Available values: `disabled`, `enabled`.
- `status_code` (Number) The status code to be used when redirecting a request.
- `subpath_matching` (String) Whether the redirect also matches subpaths of the source url. Available values: `disabled`, `enabled`.

## Import

Import is supported using the following syntax:

```shell
$ terraform import cloudflare_list.example <account_id>/<list_id>
```
